/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.open.api.core.service.processor.base.pre.callback;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import info.peigen.hotpot.common.core.result.ResultCode;
import info.peigen.hotpot.common.service.base.exception.BusinessException;
import info.peigen.hotpot.component.open.api.facade.order.OpenApiCallbackOrder;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessor;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessorServiceContext;
import org.noear.solon.annotation.Component;


/**
 * <b>(OpenApiCallbackOrderCheckProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/9/20
 */
@Component
public class OpenApiCallbackOrderCheckProcessor implements OpenApiProcessor {
    @Override
    public Integer level() {
        return 1;
    }

    @Override
    public void execute(OpenApiProcessorServiceContext serviceContext) {
        OpenApiCallbackOrder order = (OpenApiCallbackOrder) serviceContext.getOrder();
        Assert.isTrue(StrUtil.isNotEmpty(order.getCallType()), () -> new BusinessException(ResultCode.FAILURE, "order校验失败(callType)" +
                "[order=" + JSON.toJSONString(order, JSONWriter.Feature.PrettyFormat) + "]"));
        Assert.isTrue(StrUtil.isNotEmpty(order.getMethodType()), () -> new BusinessException(ResultCode.FAILURE, "order校验失败(methodType)" +
                "[order=" + JSON.toJSONString(order, JSONWriter.Feature.PrettyFormat) + "]"));
        Assert.isTrue(StrUtil.isNotEmpty(order.getBusinessType()), () -> new BusinessException(ResultCode.FAILURE, "order校验失败(businessType)" +
                "[order=" + JSON.toJSONString(order, JSONWriter.Feature.PrettyFormat) + "]"));
        Assert.isTrue(StrUtil.isNotEmpty(order.getData()), () -> new BusinessException(ResultCode.FAILURE, "order校验失败(data)" +
                "[order=" + JSON.toJSONString(order, JSONWriter.Feature.PrettyFormat) + "]"));
    }
}